fileType="received";
var mygrid;
$(function(){ 
 mygrid = $("#list").jqGrid({
		url : "fileserver/file/file-data!typedfile",
		postData:{"folder.type":"received"},
		datatype : "json",
		mtype : 'GET',
		colNames : ['选择','编辑','文件标题','类型','发送者','接收人','发送日期','管理'],
		colModel : [
		{			
			name : 'id',
			index : 'id',
			width : 30,
			formatter:selectFormatter
		},
		{
			name:"id",
			index:"id",
			width:30,
			formatter:editFormatter
		},
	    {
			name:'title',
			index:'title',
			width:150,
			formatter:downloadFormatter
	    },
		{
			name:'imgpath',
			index:'imgpath',
			width:30,
			formatter:imgFormatter
		},{
			name : 'fromer',
			index : 'fromer',
			width : 30 ,
			formatter:ownerFormatter
		}
		,{
			name : 'owner',
			index : 'owner',
			width : 30,
			formatter:ownerFormatter
		}, 
		{
			name : 'createTime',
			index : 'createTime',
			width : 90
		}, {
			name : 'id',
			index :'id',
			width : 30,
			formatter:deleteFormater
		}],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'createTime',
		sortorder : 'desc',
		viewrecords : true,
		caption : '我的已收文件',
		width : '750',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	});
 });
/**自定义formatter 函数开始**/

function imgFormatter(cellvalue, options, rowObject) {
		var img = $("<img></img>");
		img.attr("src",sbase+cellvalue);
		img.css("width","16px");
		img.css("height","16px");
		return $("<span><span>").append(img).html();
}
function ownerFormatter(c,op,row){
	 if(c!=null && typeof(c)!='undefined') return  c.localName;
    return "-";
}

function selectFormatter(cv,opt,row){
		var fid = row['id'];
		var title = row['title'];
		var link = $("<input type=\"checkbox\" onclick=\"checkFile('"+fid+"','"+title+"',this.checked);\"></input>");
	    return $("<span></span>").append(link).html();
	
}
function downloadFormatter(cellvalue, options, rowObject) {
		var eid = rowObject['id'];
		var link = $("<a></a>");
		link.attr("href", "fileserver/file/download!download?bean.id="+eid);
	    link.attr("target","_blank");
		link.html("<b>"+cellvalue+"</b>");
		return $("<span></span>").append(link).html();
	
}

function deleteFormater(cv,opt,row){
		var eid = row['id'];
		var link = $("<a></a>");
		link.attr("href", "javascript:removeMe('"+eid+"');");
		link.html("<img src='"+sbase+"images/removeme.gif' style='border:none'/>");
		return $("<span></span>").append(link).html();
}
function editFormatter(v,opt,row){
	var ftype  =row['fileType'];
	var eid = row['id'];
	var link = $("<a></a>");
	if(ftype=="doc" 
		|| ftype=="docx"
	    || ftype=="xls"
	    || ftype=="xlsx"
	    || ftype=="ppt"
	    || ftype=="pptx"){
		link.attr("href","fileserver/file/translate-file!openforedit?fileId="+eid);
	}else{
		return '-';
	}
	link.attr("target","_blank");
	link.html("<b style='color:green'>编辑</b>");
	return $("<span></span>").append(link).html();
}
 